/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.srcptit.trainning.giangnd.btvn1;

/**
 *
 * @author GIANG
 */
public class B7 {
    static boolean tn(int n) {
		int m = n, dao = 0;
		while (m > 0) {
			dao = dao * 10 + m % 10;
			m /= 10;
		}
		return n == dao;
	}

	static boolean ngto(int n) {
		if (n < 2)
			return false;
		for (int i = 2; i <= Math.sqrt(n); i++)
			if (n % i == 0)
				return false;
		return true;
	}

	static int tong(int n) {
		int t = 0;
		while (n != 0) {
			t = n % 10;
			n /= 10;
		}
		return t;
	}

	static boolean fibo(int n) {
		int i, a[] = new int[n + 1];
		a[0] = 0;
		a[1] = 1;
		for (i = 2; i <= n; i++)
			a[i] = a[i - 1] + a[i - 2];
		for (i = 0; i <= 10; i++)
			if (tong(n) == a[i])
				return true;
		return false;
	}

	public static void main(String args[]) {
		for (int i = 10000; i <= 9999999; i++)
			if (ngto(i) && tn(i) && fibo(i))
				System.out.print(i + " ");
	}

}
